home *** CD-ROM | disk | FTP | other *** search
/ Die Speccy' 97 / Die Speccy' 97.iso / amiga_system / the_aminet / util / cli / iconalign.lha / IconAlign / IconAlign.mod < prev    next >
Text File  |  1995-09-10  |  4KB  |  128 lines

  1. (*
  2. (****** IconAlign/--AMOK-Header-- *******************************************
  3.  
  4. :Program.    IconAlign.mod
  5. :Contents.   arranges Workbench icons orderly
  6. :Author.     Oliver Knorr
  7. :Copyright.  Public Domain
  8. :Language.   Oberon-2
  9. :Translator. Amiga Oberon v3.11
  10. :History.    v1.0 [olk] 10-Sep-95
  11. :Version.    $VER: IconAlign.mod 1.0 (10.9.95)
  12.  
  13. *****************************************************************************
  14. *
  15. *)
  16. *)
  17.  
  18. MODULE IconAlign;
  19.  
  20.  
  21. IMPORT
  22.  
  23.   Dos, Workbench, Icon, io, NoGuru;
  24.  
  25.  
  26. TYPE
  27.  
  28.   Args = STRUCT (as: Dos.ArgsStruct)
  29.            from       : Dos.ArgString;
  30.            to         : Dos.ArgStringArray;
  31.            horizontal : Dos.ArgBool;
  32.            vertical   : Dos.ArgBool;
  33.            distance   : Dos.ArgLong;
  34.          END;
  35.  
  36.  
  37. CONST
  38.  
  39.   template  = "FROM/A,TO/A/M,HORIZONTAL/S,VERTICAL/S,DISTANCE/N";
  40.   verString = "$VER: IconAlign 1.0 (10.9.95) by Oliver Knorr";
  41.  
  42.  
  43. VAR
  44.  
  45.   rdArgs    : Dos.RDArgsPtr;
  46.   args      : Args;
  47.   fromIcon,
  48.   toIcon    : Workbench.DiskObjectPtr;
  49.   toIndex   : INTEGER;
  50.   nextPos   : LONGINT;
  51.  
  52.  
  53. BEGIN
  54.  
  55.   IF verString[0]="$" THEN END; (* the version string shouldn't be optimized away *)
  56.  
  57.   IF Dos.base.lib.version >= 37 THEN
  58.     IF Icon.base.version >= 36 THEN
  59.  
  60.       rdArgs := Dos.ReadArgs (template, args, NIL);
  61.       IF (rdArgs # NIL) THEN
  62.         IF ((args.horizontal = Dos.DOSTRUE) & (args.vertical = Dos.DOSFALSE))
  63.         OR ((args.horizontal = Dos.DOSFALSE) & (args.vertical = Dos.DOSTRUE)) THEN
  64.           fromIcon := Icon.GetDiskObject(args.from^);
  65.           IF (fromIcon # NIL) THEN
  66.             toIndex := 0;
  67.  
  68.             IF (args.distance # NIL) THEN
  69.               IF (args.horizontal = Dos.DOSTRUE) THEN
  70.                 nextPos := fromIcon.currentX + fromIcon.gadget.width + args.distance[0] + 8
  71.               ELSE
  72.                 nextPos := fromIcon.currentY + fromIcon.gadget.height + args.distance[0] + 5
  73.               END
  74.             END;
  75.  
  76.             WHILE args.to[toIndex] # NIL DO
  77.               toIcon := Icon.GetDiskObject(args.to[toIndex]^);
  78.               IF (toIcon # NIL) THEN
  79.  
  80.                 IF (args.horizontal = Dos.DOSTRUE) THEN
  81.                   toIcon.currentY := fromIcon.currentY + fromIcon.gadget.height - toIcon.gadget.height;
  82.                   IF (args.distance # NIL) THEN
  83.                     toIcon.currentX := nextPos;
  84.                     INC(nextPos, toIcon.gadget.width+args.distance[0]+8)
  85.                   END
  86.                 ELSE
  87.                   toIcon.currentX := fromIcon.currentX + ENTIER((fromIcon.gadget.width-toIcon.gadget.width)/2);
  88.                   IF (args.distance # NIL) THEN
  89.                     toIcon.currentY := nextPos;
  90.                     INC(nextPos, toIcon.gadget.height+args.distance[0]+5)
  91.                   END
  92.                 END;
  93.  
  94.                 IF ~Icon.PutDiskObject(args.to[toIndex]^, toIcon) THEN
  95.                   io.WriteString("could not write TO icon ");
  96.                   io.WriteString(args.to[toIndex]^); io.WriteLn
  97.                 END;
  98.                 Icon.FreeDiskObject(toIcon)
  99.  
  100.               ELSE
  101.                 io.WriteString("could not read TO icon ");
  102.                 io.WriteString(args.to[toIndex]^); io.WriteLn
  103.               END;
  104.               INC(toIndex)
  105.             END;
  106.  
  107.             Icon.FreeDiskObject(fromIcon)
  108.           ELSE
  109.             io.WriteString("could not read FROM icon"); io.WriteLn
  110.           END;
  111.           Dos.FreeArgs(rdArgs)
  112.         ELSE
  113.           io.WriteString("use exactly one of HORIZONTAL/S and VERTICAL/S"); io.WriteLn
  114.         END
  115.       ELSE
  116.         io.WriteString("wrong arguments"); io.WriteLn
  117.       END
  118.  
  119.     ELSE
  120.       io.WriteString("requires icon.library V36"); io.WriteLn
  121.     END
  122.   ELSE
  123.     io.WriteString("requires dos.library V37"); io.WriteLn
  124.   END
  125.  
  126.  
  127. END IconAlign.
  128.